package com.cskt.util;

import java.math.BigDecimal;

/**
 * @author mo
 * @Description: BigDecimal的加减乘除
 * @date 2020-10-08 16:24
 */

public class BigDecimalUtil {
    /**
     * BigDecimal操作枚举定义
     */
    public enum BigDecimalOprations{
        add,subtract,multiply,divide
    }

    public static BigDecimal OpertionASMD(Object numOne,Object numTwo,BigDecimalOprations bigDecimalOprations,int scale,int roundingMode){
        BigDecimal num1 = new BigDecimal(String.valueOf(numOne)).setScale(scale,roundingMode);
        BigDecimal num2 = new BigDecimal(String.valueOf(numTwo)).setScale(scale,roundingMode);
        switch (bigDecimalOprations){
            case add:
                return num1.add(num2).setScale(scale,roundingMode);
            case subtract:
                return num1.subtract(num2).setScale(scale,roundingMode);
            case multiply:
                return num1.multiply(num2).setScale(scale,roundingMode);
            case divide:
                return num1.divide(num2).setScale(scale,roundingMode);
            default:
                break;
        }
        return null;
    }
}
